package com.ysd.lis.controller.view;


import com.ysd.common.Result;
import com.ysd.lis.controller.pub.BaseController;
import com.ysd.lis.entity.view.ViewApplyInfo;
import com.ysd.lis.request.DeleteParam;
import com.ysd.lis.service.view.ViewApplyInfoService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.sql.DataSource;
import java.sql.SQLException;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author wanghuaixing
 * @since 2025-02-13
 */
@RestController
@RequestMapping("/view/apply")
public class ViewApplyInfoController extends BaseController {

    @Autowired
    ViewApplyInfoService viewApplyInfoService;

    @ApiOperation("保存申请信息")
    @PostMapping("/saveViewApply")
    public Result saveViewApply(@RequestBody ViewApplyInfo viewApplyInfo) {
        return viewApplyInfoService.saveViewApplyInfo(viewApplyInfo);
    }

    @ApiOperation("获取视图测试执行结果")
    @PostMapping("/getViewApplyTestResultList")
    public Result getViewApplyTestResultList(@RequestBody ViewApplyInfo viewApplyInfo) throws SQLException {
        return viewApplyInfoService.getViewApplyTestResultList(viewApplyInfo);
    }

    @ApiOperation("获取视图列表带数据库视图拉取")
    @GetMapping("/getViewApplyList")
    public Result getViewApplyList(ViewApplyInfo viewApplyInfo) throws SQLException {
        return viewApplyInfoService.getViewApplyList(viewApplyInfo);
    }

    @ApiOperation("审核申请信息")
    @PostMapping("/auditViews")
    public Result auditViews(@RequestBody DeleteParam deleteParam) {
        return viewApplyInfoService.auditViews(deleteParam);
    }

    @ApiOperation("获取视图列表")
    @GetMapping("/getViewApplyDataSourceList")
    public Result getViewApplyDataSourceList(ViewApplyInfo viewApplyInfo) throws SQLException {
        return viewApplyInfoService.getViewApplyDataSourceList(viewApplyInfo);
    }

    @ApiOperation("关闭数据库视图数据")
    @PostMapping("/closeViewApplyDataSourceList")
    public Result closeViewApplyDataSourceList(@RequestBody ViewApplyInfo viewApplyInfo) throws SQLException {
        return viewApplyInfoService.closeViewApplyDataSourceList(viewApplyInfo);
    }

    @ApiOperation("关闭数据库视图数据")
    @PostMapping("/openViewApplyDataSourceList")
    public Result openViewApplyDataSourceList(@RequestBody ViewApplyInfo viewApplyInfo) throws SQLException {
        return viewApplyInfoService.openViewApplyDataSourceList(viewApplyInfo);
    }

    @ApiOperation("获取视图日志信息")
    @GetMapping("/getViewLogsByName")
    public Result getViewLogsByName(ViewApplyInfo viewApplyInfo){
        return viewApplyInfoService.getViewLogByName(viewApplyInfo);
    }
}